
/**

 * 
 * @authors hulxg
 * @date    2013-09-28 09:26:49
 * @version v1.0
 */
/*function iFrameHeight() { 
    var ifm= document.getElementById("win"); 

    var subWeb = document.frames ? document.frames["win"].document : ifm.contentDocument; 
    alert(subweb);
    if(ifm != null && subWeb != null) { 
       ifm.height = subWeb.body.scrollHeight; 
       alert();
    } 
} 
*/
(function($){
	var setting;
    $.fn.dialog = function(opts) {
    	setting = $.extend({
    		/*
    		 * 弹出框的宽度
    		 */
    		width:700,
    		/*
    		 *弹出框的高度
    		 */
    		height:300,
    		titleBackground:"#72BFE7",
    		/*
    		 *标题的高度
    		 */
    		titleHeight:25,
    		/*
    		 *要打开的新窗口的url
    		 */
    		url:"#",
    		/*
    		 *弹出框的标题
    		 */
    		title:"弹出窗口实例",
    		/*
    		 *弹出框的主题信息
    		 */
    		message:"你可以在这里输出你要输出的内容",
    		borderColor:"#72BFE7",
    		borderWidth:"6px",
    		/*
    		 *弹出框的底部高度
    		 */
    		footHeight:0.09,
            left:"400px",
            top:"400px",
            isCenter:true,
            footMessage:""

    	},opts||{});
    	init($("body"));
    	//dialogShow();
        this.hiddenDialog = hiddenDialog;
        return this;
    }

    /*
     *初始化的函数
     */
    function init(that) {
    	var node = "<div id='hg_dialog'></div>";
    	var sadeNode ="<div id='hg_sade'></div>";
    	that.append(node);
    	that.append(sadeNode);
    	/*
    	 *如果设置了url就要加载url
    	 */
    	if(setting.url !="#") {
    		setting.message = "<iframe width='100%' height='100%' align='center' id='win' name='win'"+
    		 " frameborder='0' scrolling='auto'"+ 
    		 " onload='iFrameHeight()' src='"+setting.url+"'></iframe>";


    	}
    	if(setting.titleHeight>0) {
    		var titleNode = "<div id='hg_dialog_title'><span style='float:left;margin-top:5px'>"+
    	                "</span><span style='float:left;margin-top:3px;margin-left:3px;'>"+setting.title+"</span>"+
    	                "</div>";
    	    $("#hg_dialog").append(titleNode);   


    	}
    	if(setting.url == "#") {
   
    		$("#hg_dialog_messsage").css({
    			"overflow-y":"hidden"
    		}); 
    		
    	}
    	var messageNode = "<div id='hg_dialog_message'>"+setting.message+"</div>";
    	$("#hg_dialog").append(messageNode);
        
    	if(setting.footHeight>0) {
    		var footNode = "<div id='hg_dialog_foot'>"+setting.footMessage+"</div>";
    		$("#hg_dialog").append(footNode);

    	}
    	
    	/*
    	 *设置遮罩的宽度和高度
    	 */
        $("#hg_sade").css({
    		width:$(window).width(),
    		height:$(window).height()
    	})
    	$("#hg_dialog #hg_dialog_title").css({
    		height:setting.titleHeight,
    		width:setting.width,
    		background:setting.titleBackground
    	});
    	/*
    	 *计算显示信息的高度
    	 */
    	var h =setting.height-setting.height*setting.footHeight-setting.titleHeight;
    	$("#hg_dialog #hg_dialog_message").css({
    		height:h
    	});

    	
    	$("#hg_dialog_foot").css({
    		height:setting.footHeight*100+"%"
    	})
        /*
         *如果设置居中那么设置的left和top参数就不起作用了，而是会居中
         */
        if(!setting.isCenter) {
            $("#hg_dialog").css({
                height:setting.height,
                width:setting.width,
                position:"absolute",
                "border-color":setting.borderColor,
                top:setting.top,
                left:setting.left
           });
        }else{
           $("#hg_dialog").css({
                height:setting.height,
                width:setting.width,
                position:"absolute",
                "border-color":setting.borderColor,
                top:"50%",
                left:"50%",
                "margin-top":-1*setting.height/2,
                "margin-left":-1*setting.width/2
    
           });

        }
    	
    	
    	$("#hg_closeDialog").mouseover(function(event) {
    		   $(this).attr("src","images/dialog_closebtn_over.gif");
    	}).mouseout(function(event) {
    		$(this).attr("src","images/dialog_closebtn_over.png");
    	}).click(hiddenDialog).css("cursor","pointer");

    	$("#hg_dialog_title").mouseover(function(event) {
    		$(this).css("cursor","Move");
    	});

    	/*$("#win").load(function(){
    		var h = $(this).contents().find("body").height() + 40;
    		//alert($(this).contents().find("#content").height());
    		//var subWeb = document.frames ? document.frames["win"].document : this.contentDocument; 
    		//var subWeb = document.frames ? document.frames["win"].document : this.contentDocument; 
    		//var h = subWeb.body.scrollHeight+50;
    		//alert(h);
    		 //var contentHeight=this.contentDocument?this.contentDocument.body.scrollHeight:this.Document.body.offsetHeight;//w.contentDocument:netscape,w.document:ie
               // $(this).css("height",contentHeight);
    		//$(this).height(h);
    		
    	});*/

    	$("#hg_dialog_title").mousedown(function(event) {
             var l = $("#hg_dialog").css("left");
            var  t = $("#hg_dialog").css("top");
    		 l = event.pageX-parseInt(l);
    		 t = event.pageY-parseInt(t);

    		$(this).mousemove(function(event) {
    			var ml = event.pageX-l;
    			var mt = event.pageY-t
	    		$("#hg_dialog").css({
	           	   left:ml,
	           	   top:mt
	           });

    	    });

	    	$("#hg_dialog_title,#hg_dialog,body").mouseup(function(event) {
	    		$("#hg_dialog_title").off("mousemove");
	    	}).mouseout(function(event) {
	    		$(this).off("mousemove");
	    	});

      });
    }

    function hiddenDialog() {
            $("#hg_sade").hide();
            $("#hg_dialog").hide();
            $("#hg_sade").remove();
            $("#hg_dialog").remove();
    }


})(jQuery);

(function($){
        $.fn.myconfirm = function(opts) {
       var  set = $.extend({
            /*
             * 弹出框的宽度
             */
            width:700,
            /*
             *弹出框的高度
             */
            height:300,
            /*
             *标题的高度
             */
            titleHeight:25,

    
            /*
             *弹出框的标题
             */
            title:"弹出窗口实例",
            /*
             *弹出框的主题信息
             */
            message:"你可以在这里输出你要输出的内容",
            /*
             *弹出框的底部高度
             */
            footHeight:0.09,
            left:"400px",
            top:"400px",
            isCenter:true

        },opts||{});
       var h =set.height-set.height*set.footHeight-set.titleHeight;
       var t = parseInt(h)/4;
       set.message="<div style='margin-top:"+t+"px;'><span><img src='images/icon_query.gif'/></span><div style='margin-top:15px;font-weight:bolder;'>确定要删除吗?</div></div>";
       set.footMessage="<button class='hg_confirm' >确定</button>                   <button class='hg_confirm'>取消</button>"
       var obj = this.dialog(set);
       var that = this;
       $(".hg_confirm").click(function(){
            obj.hiddenDialog();

            if($(this).html()=="确定"){
                window.location.href=that.attr("href");
                return true;

            }
       });
    }
})(jQuery);


